import json
import os
from config import BASE_PATH

"""
一些公共方法
"""


# 读取json测试数据
# def read_json(filename,key):
#     filePath = BASE_PATH + os.sep + "data" + os.sep + filename
#     with open(filePath,encoding="utf-8") as f:
#         #读取json数据
#         json_data = json.load(f) #数据转换成 [(),()]
#         list = []
#         #遍历
#         for data in json_data.get(key):
#             list.append(tuple(data.values()))
#         return list

# 读取json
def read_json(filename):
    filePath = BASE_PATH + os.sep + "data" + os.sep + filename
    with open(filePath, encoding="utf-8") as f:
        # 读取json数据
        json_data = json.load(f)  # 数据 [[],[]]
        return json_data


# 写入json
def write_json(filename, data):
    filepath = BASE_PATH + os.sep + "data" + os.sep + filename
    with open(filepath, "w", encoding="utf-8")as f:
        json.dump(data, f, ensure_ascii=False, indent=2)